package com.atguigu.springcloud.entities;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
  * 统一返回对象
  *
  * @author hyman
  * @date  20:26
  * @since 最早从哪个版本开始的，如v1.0.1
  */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {
    private Integer code;
    private String message;
    private T data;


    public CommonResult(Integer code, String message) {
        this.code = code;
        this.message = message;
        data = null;
    }

    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<>(200, message, data);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(200, "", data);
    }

    public static <T> CommonResult<T> success(String message) {
        return CommonResult.success(message, null);
    }

    public static <T> CommonResult<T> failure(Integer code, String message) {
        return new CommonResult<>(code, message, null);
    }

    @Override
    public String toString() {
        return "CommonResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
